package com.heisen.uua.enhancer;

import com.google.common.collect.Maps;
import com.heisen.base.constant.HttpConstant;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 令牌  增强器
 */
@Component
public class CustomTokenEnhancer implements TokenEnhancer {



    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        if (accessToken instanceof DefaultOAuth2AccessToken) {
            String grantType = authentication.getOAuth2Request().getGrantType();

            HashMap<String, Object> map = Maps.newHashMap();
            map.put("code", HttpConstant.HttpCode.SC_OK);
            map.put("Beare", "Beare " + accessToken.getValue());
            ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(map);


        }

        return accessToken;
    }


}